//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "Thirty360.h"
using namespace Cephei::QL::Times::Daycounters;
#include <gen/QL/Times/DayCounter.h>
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Times::Daycounters::CThirty360::CThirty360 (Microsoft::FSharp::Core::FSharpOption<QL::Times::Daycounters::Thirty360::ConventionEnum>^ c) : CDayCounter(CThirty360::typeid)
{
    try
    {
#ifdef HANDLE
        _phThirty360 = NULL;
#endif
        QuantLib::Thirty360::Convention _c = 
            (Microsoft::FSharp::Core::FSharpOption<QL::Times::Daycounters::Thirty360::ConventionEnum>::IsSome::get (c) ? (QuantLib::Thirty360::Convention)c->Value : QuantLib::Thirty360::Convention::BondBasis); //10
        _ppThirty360 = new boost::shared_ptr<QuantLib::Thirty360> (new QuantLib::Thirty360 ( _c ));
        SetDayCounter (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppThirty360));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Times::Daycounters::CThirty360::CThirty360 (boost::shared_ptr<QuantLib::Thirty360>& childNative, Object^ owner) : CDayCounter(CThirty360::typeid)
{
#ifdef HANDLE
	_phThirty360 = NULL;
#endif
	_ppThirty360 = &childNative;
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppThirty360));
}
Cephei::QL::Times::Daycounters::CThirty360::CThirty360 (QuantLib::Thirty360& childNative, Object^ owner) : CDayCounter(CThirty360::typeid)
{
#ifdef HANDLE
	_phThirty360 = NULL;
#endif
	_ppThirty360 = new boost::shared_ptr<QuantLib::Thirty360> (&childNative);
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppThirty360));
    _Thirty360Owner = owner;
    _DayCounterOwner = owner;
}

Cephei::QL::Times::Daycounters::CThirty360::CThirty360 (CThirty360^ copy) : CDayCounter(CThirty360::typeid)
{
#ifdef HANDLE
	_phThirty360 = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppThirty360 = new boost::shared_ptr<QuantLib::Thirty360> (copy->GetShared());
        _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppThirty360));
    }
}
Cephei::QL::Times::Daycounters::CThirty360::CThirty360 (PLATFORM::Type^ t) : CDayCounter(CThirty360::typeid)
{
#ifdef HANDLE
	_phThirty360 = NULL;
#endif
	if (!t->IsSubclassOf(CThirty360::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Times::Daycounters::CThirty360::CThirty360 (QuantLib::Handle<QuantLib::Thirty360>& childNative, Object^ owner)  : CDayCounter(CThirty360::typeid)
{
	_phThirty360 = &childNative;
	_ppThirty360 = &static_cast<boost::shared_ptr<QuantLib::Thirty360>>(childNative.currentLink());
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppThirty360));
    _Thirty360Owner = owner;
}
Cephei::QL::Times::Daycounters::CThirty360::CThirty360 (QuantLib::Handle<QuantLib::Thirty360> childNative)  : CDayCounter(CThirty360::typeid)
{
	_phThirty360 = &childNative;
	_ppThirty360 = &static_cast<boost::shared_ptr<QuantLib::Thirty360>>(childNative.currentLink());
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppThirty360));
}
#endif
#ifdef STRUCT
Cephei::QL::Times::Daycounters::CThirty360::CThirty360 (QuantLib::Thirty360 childNative)  : CDayCounter(CThirty360::typeid)
{
#ifdef HANDLE
	_phThirty360 = NULL;
#endif
	_ppThirty360 = new boost::shared_ptr<QuantLib::Thirty360> (new QuantLib::Thirty360 (childNative));
    _ppDayCounter = new boost::shared_ptr<QuantLib::DayCounter> (boost::dynamic_pointer_cast<QuantLib::DayCounter> (*_ppThirty360));
}
#endif

Cephei::QL::Times::Daycounters::CThirty360::~CThirty360 ()
{
    if (_ppThirty360 != NULL)
    {
	    delete _ppThirty360;
        _ppThirty360 = NULL;
    }
}
Cephei::QL::Times::Daycounters::CThirty360::!CThirty360 ()
{
    if (_ppThirty360 != NULL)
    {
	    delete _ppThirty360;
    }
}
QuantLib::Thirty360& Cephei::QL::Times::Daycounters::CThirty360::GetReference ()
{
    if (_ppThirty360 == NULL) throw REFNEW NativeNullException ();
	return **_ppThirty360;
}
boost::shared_ptr<QuantLib::Thirty360>& Cephei::QL::Times::Daycounters::CThirty360::GetShared ()
{
    if (_ppThirty360 == NULL) throw REFNEW NativeNullException ();
	return *_ppThirty360;
}
QuantLib::Thirty360* Cephei::QL::Times::Daycounters::CThirty360::GetPointer ()
{
    if (_ppThirty360 == NULL) throw REFNEW NativeNullException ();
	return &**_ppThirty360;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::Thirty360>& Cephei::QL::Times::Daycounters::CThirty360::GetHandle ()
{
	if (_phThirty360 == NULL)
	{
		_phThirty360 = new Handle<QuantLib::Thirty360> (*_ppThirty360);
	}
	return *_phThirty360;
}
#endif
bool Cephei::QL::Times::Daycounters::CThirty360::HasNative () 
{
	return (_ppThirty360 != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Times::Daycounters::IThirty360^ Cephei::QL::Times::Daycounters::CThirty360_Factory::Create (Microsoft::FSharp::Core::FSharpOption<QL::Times::Daycounters::Thirty360::ConventionEnum>^ c)
{
    return REFNEW CThirty360 ( c);
}
